// #define print(...)
class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        if(strs.empty()) return "";
        string::iterator head = strs[0].begin(),
            rear = head + strs[0].size();
        for(auto it=strs.begin()+1; it!=strs.end(); it++){
            auto i1 = head;
            for(auto i2 = it->begin(); i2!=it->end() && i1!=rear; i2++){
                if(*i1 != *i2) break;
                i1++;
            }
            if(rear > i1) rear = i1;
            if(rear == head) return "";
        }
        return strs[0].substr(0, rear-head);
    }
};